#! /bin/bash

echo "当前执行文件......$0"
##################################变量定义##################################
#需要安装软件集合
softwares="zip unzip";
#是否安装docker
isDocker=true;
#修改docker存储位置(空不修改)
dockerGraph="";
#是否安装Nginx
isNginx=true;
#是否安装docker-compose
isDockderCompose=true;
#https://github.com/docker/compose/releases

if [ $? == 0 ];then
		echo -e "\n Start";
		
		sudo yum update -y;
		
		if [ -x "$(command -v mari*)" ]; then
			sudo yum -y remove mari*;
		fi
		for software in $softwares;do
			if ! [ -x "$(command -v $software)" ]; then
				yum install -y $software;
			fi
		done
		if [ $isDocker = true ]; then
			if ! [ -x "$(command -v docker)" ]; then
				yum install -y yum-utils device-mapper-persistent-data;
				yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo;
				yum -y install docker-ce;
				systemctl enable docker;
				
				if [ -d "$dockerGraph" ] && [ -d '/etc/docker' ]; then
					if [ ! -f '/etc/docker/daemon.json' ]; then
						sudo touch /etc/docker/daemon.json;
					fi
				
					echo -e "{" > /etc/docker/daemon.json;
				
					echo -e "\t\"graph\":\"${dockerGraph}\"" >> /etc/docker/daemon.json;
				
					echo -e "}" >> /etc/docker/daemon.json;
					
					sudo systemctl daemon-reload;
				fi
				
				systemctl start docker;
			fi
		fi
		if [ $isNginx = true ]; then
			if ! [ -x "$(command -v nginx)" ]; then
				rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm;
				yum install -y nginx;
				systemctl start nginx.service;
				systemctl enable nginx.service;
			fi
		fi
		if [ $isDockderCompose = true ]; then
			if ! [ -x "$(command -v docker-compose)" ]; then
				curl -L https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose;
				chmod +x /usr/local/bin/docker-compose;
			fi
		fi
		
		sudo echo > /root/.bash_history;
		echo -e "\n Success";
	else
		echo -e "\n Error";
fi
